package java_DesignPattern.BehavioralPattern.IteratorPattern;

import java.util.List;

/**
 * 学生迭代器类，实现了迭代器接口，用于遍历学生列表
 */
public class StudentIterator implements Iterator<Student> {

    private List<Student> list;
    private int index = 0;//当前遍历的索引位置

    public StudentIterator(List<Student> list) {
        this.list = list;
    }

    @Override
    public boolean hasNext() {
        return index < list.size();
    }

    @Override
    public Student next() {
        return list.get(index++);
    }
}
